Public Class frmBArticulos
    Dim MiGestDatos As GestDatos
    Dim MiCursorRaton As New GestProyecto
    Private Sub frmClientes_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

        MiCursorRaton.CursorRaton(True)

        Dim Ruta As String
        Ruta = "Data Source =" & System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) & "\DBGestion.sdf;"
        Dim LineaSQL(0) As String
        Dim Tabla(0) As String
        LineaSQL(0) = "Select CodArt,Articulo,TipoIVAIR,Stock,Precio1,CodIVARE,IVA,RE From Articulos, TiposIVARE"
        Tabla(0) = "Articulos"

        MiGestDatos = New GestDatos
        MiGestDatos.ConextarBD(Ruta, LineaSQL, Tabla)

        MostrarDatosGrid("")

        MiCursorRaton.CursorRaton(False)

    End Sub

    Private Sub cboFArticulos_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboFArticulos.TextChanged

        MiCursorRaton.CursorRaton(True)

        If cboFArticulos.Text = "NINGUN FILTRO" Then
            txtFArticulos.Enabled = False
            btnFArticulos.Enabled = False
            MostrarDatosGrid("")
            txtFArticulos.Text = ""
        Else
            txtFArticulos.Enabled = True
            btnFArticulos.Enabled = True
        End If

        If Not cboFArticulos.Text = "NINGUN FILTRO" Then
            txtFArticulos.Focus()
        End If

        MiCursorRaton.CursorRaton(False)

    End Sub


    Sub MostrarDatosGrid(ByVal Condicion As String)
        Dim MiCursorRaton As New GestProyecto

        If Not Condicion = "" Then
            Condicion = "TipoIVAIR = CodIVARE" & Condicion
        Else
            Condicion = "TipoIVAIR = CodIVARE"
        End If

        Dim grdEmcabezados As New GestDatos.Emcabezados

        grdEmcabezados.add(New GestDatos.Emcabezado("CodArt", "CODIGO", 60))
        grdEmcabezados.add(New GestDatos.Emcabezado("Articulo", "ARTICULOS", 154))

        MiGestDatos.DatosGrid(grdArticulos, grdEmcabezados, "Articulos", Condicion)


    End Sub

    Private Sub btnFArticulos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFArticulos.Click

        MiCursorRaton.CursorRaton(True)

        If Not txtFArticulos.Text = "" Then
            Dim MiCondicion As String

            If cboFArticulos.Text = "NOMBRE" Then
                MiCondicion = " AND Articulo Like '" & CStr(txtFArticulos.Text) & "%'"
            Else
                MiCondicion = " AND CodArt Like '" & CStr(txtFArticulos.Text) & "%'"
            End If

            MostrarDatosGrid(MiCondicion)

        End If

        MiCursorRaton.CursorRaton(False)

    End Sub

    Private Sub grdArticulos_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdArticulos.Click

        MiCursorRaton.CursorRaton(True)

        grdArticulos.Select(grdArticulos.CurrentRowIndex)

        MiCursorRaton.CursorRaton(False)

    End Sub

    Private Sub grdArticulos_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdArticulos.DoubleClick

        MiCursorRaton.CursorRaton(True)

        If lblFormulario.Text = "Pedidos" Then
            MostrarDatosArt(grdArticulos.CurrentRowIndex.ToString)
        Else
            frmDClientes.txtCod.Text = grdArticulos.Item(grdArticulos.CurrentRowIndex, 0).ToString
            frmDClientes.ShowDialog()
        End If

        MiCursorRaton.CursorRaton(False)

    End Sub
    Private Sub MostrarDatosArt(ByVal Indice As Integer)

        If MiGestDatos.DataSet Is DBNull.Value Then
            MsgBox("Es nulo")
        End If
        'grdArticulos.migestiondatos._MiDataView.
        With MiGestDatos.DataView.ToTable
            If Not grdArticulos.VisibleRowCount = 0 Then '.Rows.Count = 0 Then
                'If .Rows(Indice)("Stock") = 0 Then
                'MsgBox("No hay Stock")
                'Else
                frmInicio.MifrmLineaPed.txtCodigo.Text = .Rows(Indice)("CodArt")
                frmInicio.MifrmLineaPed.txtArticulo.Text = .Rows(Indice)("Articulo")
                frmInicio.MifrmLineaPed.txtIVA.Text = .Rows(Indice)("IVA")
                frmInicio.MifrmLineaPed.txtRE.Text = .Rows(Indice)("RE")
                frmInicio.MifrmLineaPed.txtPB.Text = .Rows(Indice)("Precio1")
                Me.Dispose()
            End If
            'End If
        End With
        Me.Dispose()
    End Sub

    Private Sub mnuSalirArt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSalirArt.Click
        Me.Dispose()
    End Sub

End Class